require('./index.css')
require('page/common/top-head-menu/index.js')
require('page/common/head-search/index.js')
require('page/common/footer/index.js')
require('page/common/bread-menu/index.js')
require('page/common/right-easy-menu/index.js')
import validate from 'jquery-validation';
import _mm from 'util/mm.js'
import _tool from 'util/tool';
import _all from 'service/all-service';
const page ={
    pageData: {
        page:1,
        limit:100,
        typeId: _mm.getUrlParam('pId')
    },
    init() {
        this.initMainList();
        this.bindEvent();
    },
    initMainList() {
        const _this = this;
        $('.mainName').html($('.bread-menu-con ul li:last-child>a').html());
        const tpl = require('./mainProductList.string');
        _all.getMainProduct(this.pageData, res=> {
            $('.product-content').html(_mm.renderHtml(tpl, {data: _this.handle(res.data.rows)}));
        },err => {
            _tool.msgShakeLayer('出错啦！');
        })
    },
    bindEvent() {
        const addBmenu = function () {
            const $this = $(this);
            _tool.pushNode($this);
        };
        $('.product-con').on('click', '.product-item a', addBmenu);
        $('.product-con').on('click', '.product-name a', addBmenu);
    },
    handle(data) {
        if(data.length !==0) {
            for (let i = 0; i < data.length; i++) {
                data[i].pid = this.pageData.typeId;
            }
            console.log(data);
            return data;
        }
    }
};

module.export = page.init();